package team.bluepen.supermarket.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import team.bluepen.supermarket.common.HttpResponseEntity;
import team.bluepen.supermarket.data.entity.Product;
import team.bluepen.supermarket.service.recommend.RecommendService;

import java.util.List;

/**
 * @author RollW
 */
@RestController
@RequestMapping("/api/recommend")
public class RecommendController {
    private final RecommendService recommendService;

    public RecommendController(RecommendService recommendService) {
        this.recommendService = recommendService;
    }

    @GetMapping("/user/{userId}")
    public HttpResponseEntity<List<Product>> recommendByUser(
            @PathVariable("userId") long userId) {
        List<Product> products = recommendService.recommendByUser(userId);
        return HttpResponseEntity.success(products);
    }

    @GetMapping("/product/{productId}")
    public HttpResponseEntity<List<Product>> recommendByProduct(
            @PathVariable("productId") long productId) {
        List<Product> products = recommendService.recommendByProduct(productId);

        return HttpResponseEntity.success(products);
    }
}
